package com.zzyl.task;

import com.zzyl.mapper.ReservationMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 定时取消超时的预约计划
 */
@Component
@Slf4j
public class ReservationTask {
    @Autowired
    private ReservationMapper reservationMapper;
    /**
     * 定时任务 每隔5秒触发一次
     */
    @Scheduled(cron = "0 1/31 * * * ?")
    public void executeTask(){
        log.info("定时任务开始执行：{}", LocalDateTime.now());
        //将过期的预约日期全改为取消状态
        reservationMapper.cancelTimeoutReservation(LocalDateTime.now());

    }
}
